package tep;

import java.util.*;

public class ch1 {

    public int removeDuplicates(int[] nums) {
        int num = Integer.MAX_VALUE;
        int sum = 1;
        int j = 0;
        for(int i=0;i<nums.length;i++){
            if(nums[i]!=num){
                num = nums[i];
                sum = 1;
                nums[j] = num;
                j++;
            }else {
                if(sum==1){
                    nums[j] = num;
                    sum++;
                    j++;
                }else {
                    sum++;
                }
            }
        }
        return j;
    }



    public String simplifyPath(String path) {
        LinkedList<String> stack = new LinkedList<String>();
        StringBuilder sb = new StringBuilder();

        for(int i=0;i<path.length();i++){
            char ch = path.charAt(i);
            if(ch == '/' || i==path.length()-1){
                if(!sb.isEmpty()){
                    String str = sb.toString();
                    if(str.equals(".")){
                        sb.delete(0,sb.length());
                    }else if(str.equals("..")){
                        if(!stack.isEmpty()){
                            stack.removeLast();
                        }
                        sb.delete(0,sb.length());
                    }else {
                        stack.addLast(str);
                        sb.delete(0,sb.length());
                    }
                }
            }else {
                sb.append(ch);
            }
        }
        if(stack.isEmpty()){
            return "/";
        }
        sb.delete(0,sb.length());
        for(String s:stack){
            sb.append("/").append(s);
        }
        return sb.toString();



    }

    {

        PriorityQueue<Integer> queue = new PriorityQueue<>();
        
    }

}
